package hhh.app.domain.interactor;

import hhh.app.common.rxjava.SchedulersCompat;
import rx.Observable;
import rx.Subscriber;
import rx.Subscription;
import rx.subscriptions.Subscriptions;

/**
 * Created by hhh on 2016/12/12.
 */
public abstract class ProductCase {
    private Subscription subscription= Subscriptions.empty();

    protected abstract Observable buildProductCaseSubscriber();

    public void execute(Subscriber caseSubscriber){
        this.subscription=this.buildProductCaseSubscriber()
                .compose(SchedulersCompat.io_main())
                .subscribe(caseSubscriber);
    }

    public void unsubscribe(){
        if(!subscription.isUnsubscribed()){
            subscription.unsubscribe();
        }
    }


}
